package com.cy.pj.sys.controller;

import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.sys.entity.SysOrder;
import com.cy.pj.sys.service.SysOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description 订单操作接口类
 * @author dxy 2216874549@qq.com
 * @date 2019/12/8 21:45
 * @version 1.0
 * @since 1.8
 */
@RestController
@RequestMapping("/order")
public class SysOrderController {
    @Autowired
    private SysOrderService sysOrderService;

    @PostMapping("/save")
    public JsonResult save(@RequestBody SysOrder sysOrder){
        sysOrderService.save(sysOrder);
        return new JsonResult("保存成功");
    }

    /**
     * @description 订单列表分页查询
     * @author dxy 2216874549@qq.com
     * @date 2019/12/11 21:46
     * @param []
     * @return com.cy.pj.common.vo.JsonResult
     * @version 1.0
     * @since 1.8
     */
    @GetMapping("/doFindByPage")
    public JsonResult findByPage(){
        HttpServletRequest request =
                ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();//获取request对象
        Integer pageCurrent = Integer.parseInt(request.getParameter("page_current"));//当前页码
        Integer pageSize = Integer.parseInt(request.getParameter("page_size"));//分页大小
        String orderName = request.getParameter("order_name");//订单名称
        List<Object> data = sysOrderService.findByPage(pageCurrent,pageSize,orderName);
        return new JsonResult(data);
    }


}
